using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using NHibernate.Expression;
using System.Collections;
using NHibernate;

namespace Ghasam.Business.DAO.Impl
{
    public class CustomerDao : DaoBase<Customer>, ICustomerDao
    {

        #region ICustomerDao Members

        public int CountCustomersByExample(Customer customer)
        {
            Example example = Example.Create(customer).ExcludeZeroes()
                                .ExcludeNulls()
                                .EnableLike(MatchMode.Anywhere);


            ICriteria crit = base.Session.CreateCriteria(typeof(Customer));
            crit.SetProjection(Projections.Count("Id"));
            return crit.Add(example).UniqueResult<int>();
        }

        public IList<Customer> GetCustomerByExample(Customer customer, int pageSize, int pageNumber)
        {
            Example example = Example.Create(customer).ExcludeZeroes()
                                .ExcludeNulls()              
                                .EnableLike(MatchMode.Anywhere);
            return base.Session.CreateCriteria(typeof(Customer))
                       .SetMaxResults( pageSize ).SetFirstResult( pageSize * pageNumber )
                       .Add(example).List<Customer>();
        }
        public IList<Customer> SortCustomer(string param, bool asc)
        {
            Order dir = new Order(param, asc);
            ICriteria crit = base.Session.CreateCriteria(typeof(Customer));
            crit.AddOrder(dir);
            return crit.List<Customer>();
        }

        #endregion
    }
}
